import request from '@/utils/request'

export async function getList(name) {
  return request({
    url: '/resource/getResourceTree?name=' + name,
    method: 'get',
  })
}
//
export async function getFlatList() {
  return request({
    url: '/resource/list',
    method: 'post',
    data: {},
  })
}

export function queryListByRoleId(roleId) {
  // const url = '/resource/queryListByRoleId'
  // return $axios.post(url, params)
  return request({
    url: '/resource/queryListByRoleId',
    method: 'post',
    data: { roleId: roleId },
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
    },
  })
}
export function getResourceListPage(data) {
  return request({
    url: '/resource/queryPage',
    method: 'post',
    data,
  })
}
export function updateResource(data) {
  return request({
    url: '/resource/updateWithoutNull',
    method: 'post',
    data,
  })
}
export function addOrUpdateResource(data) {
  return request({
    url: '/resource/saveOrUpdate',
    method: 'post',
    data,
  })
}
export function doDelete(id) {
  // const url = '/resource/deleteById'
  // return $axios.post(url, params)
  return request({
    url: '/resource/deleteById?id=' + id,
    method: 'delete',
  })
}

export async function assignResource(data) {
  // const url = '/resource/deleteById'
  // return $axios.post(url, params)
  return request({
    url: '/user/assignResource',
    method: 'post',
    data,
  })
}
